package com.zcyr.core.sql.statement;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.statement.SQLDropDatabaseStatement;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.zcyr.core.sql.visitor.OGASTVisitor;
import com.zcyr.core.sql.visitor.OGOutputVisitor;

import java.util.ArrayList;
import java.util.List;

/**
 * 适用于opengauss的drop schema statement
 */
public class OGDropSchemaStatement extends SQLDropDatabaseStatement {

    private SQLExpr schema;
    private ArrayList<SQLName> schemas;

    public SQLExpr getSchema() {
        return schema;
    }

    public void setSchema(SQLExpr schema) {
        if (schema != null) {
            schema.setParent(this);
        }
        this.schema = schema;
    }

    public ArrayList<SQLName> getSchemas() {
        return schemas;
    }

    public void setSchemas(ArrayList<SQLName> schemas) {
        this.schemas = schemas;
    }

    protected void accept0(SQLASTVisitor visitor) {
        if (visitor instanceof OGASTVisitor) {
            accept0((OGASTVisitor) visitor);
        } else {
            super.accept0(visitor);
        }
    }

    public void accept0(OGASTVisitor visitor) {
        if (visitor.visit(this)) {
            acceptChild(visitor, this.schema);
        }
        visitor.endVisit(this);
    }

    @Override
    public List<SQLObject> getChildren() {
        List<SQLObject> children = new ArrayList<>();
        if (schema != null) {
            children.add(schema);
        }
        return children;
    }

    public String toString(){
        StringBuilder out = new StringBuilder();
        this.accept(new OGOutputVisitor(out));
        return out.toString();
    }
}
